package com.kzj.laimeimei.activity;

import android.os.Bundle;
import android.view.View;

import com.kzj.laimeimei.R;
import com.kzj.laimeimei.global.App;
import com.kzj.laimeimei.global.Constant;
import com.kzj.laimeimei.recyclerCard.basic.MaterialListView;
import com.kzj.laimeimei.recyclerCard.card.other.SuggestCard;
import com.kzj.laimeimei.request.BaseResponse;
import com.kzj.laimeimei.request.ICallBackForRequestServer;
import com.kzj.laimeimei.request.RequestServerManager;
import com.umeng.analytics.MobclickAgent;


public class SuggestActivity extends GBaseActivity {
    private MaterialListView material_listview;
    private SuggestCard suggestCard;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setContentViewFor720_1280(R.layout.template_materlistview);
        findViewByIds();
        initDatas();
        fillArrayInListView();
    }

    @Override
    protected void findViewByIds() {
        material_listview = (MaterialListView) findViewById(R.id.material_listview);
    }

    @Override
    protected void initDatas() {
        setTopTitle("意见反馈");
        setLeftImg(View.VISIBLE, R.drawable.back);
        setRightText(View.VISIBLE, "提交");
    }

    @Override
    protected void fillArrayInListView() {
        suggestCard = new SuggestCard(this);
        material_listview.add(suggestCard);
    }


    private void TaskSuggest(String content) {
        RequestServerManager.getInstance().handleMethod((GBaseActivity) getActivity(), null, null, false,
                Constant.getRootUrl() + Constant.Action.Action_Suggest, RequestServerManager.getInstance().
                        getRequestParams(Constant.Action.Action_Suggest, content), BaseResponse.class, new ICallBackForRequestServer<BaseResponse>() {
                    @Override
                    public void onSuccess(BaseResponse result) {
                        App.showToast("建议提交成功！");
                        SuggestActivity.this.finish();
                    }

                    @Override
                    public void onFail(int type, String errorMsg, String json) {
                        App.getInstance().showToast(errorMsg + "");
                    }
                });
    }

    @Override
    public void doClickRightText() {
        super.doClickRightText();
        if (suggestCard.getSuggest() == null || suggestCard.getSuggest().equals("")) {
                App.getInstance().showToast("内容不能为空哦" + "");
        } else {
            TaskSuggest(suggestCard.getSuggest());
        }
    }
    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart(getClass().getSimpleName()); //统计页面(仅有Activity的应用中SDK自动调用，不需要单独写)
        MobclickAgent.onResume(this);          //统计时长
    }
    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd(getClass().getSimpleName()); // （仅有Activity的应用中SDK自动调用，不需要单独写）保证 onPageEnd 在onPause 之前调用,因为 onPause 中会保存信息
        MobclickAgent.onPause(this);
    }
}
